﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using HREDU;
using HREDU.Hoang_Tuan.Classes;

namespace HREDU.Hoang_Tuan
{
    public partial class frmQTDT : Form
    {
        
        //frmNHANSU frmParent;
        /// <summary>
        /// Id của nhân viên
        /// </summary>
        public int _ID_NHANVIEN;
        /// <summary>
        /// Cho biết có refresh lại datagrid hay không
        /// </summary>
        public bool _isRefresh = false;
        CCTQTDT objCTQTDT;

        public frmQTDT()
        {
            InitializeComponent();
        }


        public frmQTDT(int ID_NHANVIEN)
        {
            InitializeComponent();
            //frmParent = frm;
            _ID_NHANVIEN = ID_NHANVIEN;
        }

        public frmQTDT(int ID_NHANVIEN, int _id_ctqtdt)
        {
            InitializeComponent();
            //frmParent = frm;
            _ID_NHANVIEN = ID_NHANVIEN;
            objCTQTDT = CCTQTDTCollection.LayObjectTheoID(_id_ctqtdt);
        }

        private void frmQTDT_Load(object sender, EventArgs e)
        {
            //Hình thức khen thưởng
            string strSQL = "select * from view_HeDaoTao";
            DataSet ds = MITI.BaseDB.Instance.ExecSql_DataSet(strSQL);
            cmbHinhThuc.ValueMember = "ID";
            cmbHinhThuc.DisplayMember = "TEN";
            cmbHinhThuc.DataSource = ds.Tables[0].DefaultView;

            //Văn bằng chứng chỉ
            strSQL = "select * from view_VanBang";
            ds = MITI.BaseDB.Instance.ExecSql_DataSet(strSQL);
            cmbVanBang.ValueMember = "ID";
            cmbVanBang.DisplayMember = "TEN";
            cmbVanBang.DataSource = ds.Tables[0].DefaultView;

            if (objCTQTDT != null)
            {
                txtTruong.Text = objCTQTDT.TRUONG;
                txtChuyenNganh.Text = objCTQTDT.CHUYENNGANH;
                cmbHinhThuc.SelectedValue = objCTQTDT.ID_HDT;
                txtTuNam.Text = objCTQTDT.TUNAM;
                txtDenNam.Text = objCTQTDT.DENNAM;
                cmbVanBang.SelectedValue = objCTQTDT.ID_VB;
            }
            else
                objCTQTDT = new CCTQTDT();
        }

        private void btnGhi_Click(object sender, EventArgs e)
        {
            objCTQTDT.ID_NHANVIEN = _ID_NHANVIEN;
            objCTQTDT.TRUONG = txtTruong.Text;
            objCTQTDT.CHUYENNGANH = txtChuyenNganh.Text;
            objCTQTDT.ID_HDT = (int)cmbHinhThuc.SelectedValue;
            objCTQTDT.TUNAM = txtTuNam.Text;
            objCTQTDT.DENNAM = txtDenNam.Text;
            objCTQTDT.ID_VB = (int)cmbVanBang.SelectedValue;
            
            if (objCTQTDT.ID_CTQTDT > 0)
            {
                if (CCTQTDTCollection.Update(objCTQTDT) > 0)
                    MessageBox.Show("Cập nhật thành công.");
            }
            else
            {
                if (CCTQTDTCollection.Insert(objCTQTDT) > 0)
                    MessageBox.Show("Thêm thành công.");
            }
            //frmParent.LoadDataGridJanusQTDT();
            _isRefresh = true;
            
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}